function maxArea(height: number[]): number {
    let max = 0;
    let line = 0;
    let left = 0;
    let right = height.length - 1;
    while (left < right) {
        if (height[left] > height[right]) {
            if (height[right] > line) {
                line = height[right];
                let area = height[right] * (right - left);
                if (area > max) {
                    max = area;
                }
            }
            right--;
        } else {
            if (height[left] > line) {
                line = height[left];
                let area = height[left] * (right - left);
                if (area > max) {
                    max = area;
                }
            }
            left++;
        }
    }
    return max;
};

let t1 = [1, 8, 6, 2, 5, 4, 8, 3, 7];
let t2 = [1, 1];
let t3 = [4, 3, 2, 1, 4];
let t4 = [1, 2, 1];

console.log(maxArea(t1));
console.log(maxArea(t2));
console.log(maxArea(t3));
console.log(maxArea(t4));